import random  
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
  
# 生成一个6位随机数  
def create_6_verify_code():
    return random.randint(100000, 999999)  

# 发送验证码
def send_sms_code(phone_num,verify_code):

    client = AcsClient('LTAI4G1JqvT6xp8vE***', 'y5L5cm1FJEKhvG6N932IwSYP***', 'cn-hangzhou')
 
    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('dysmsapi.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https') # https | http
    request.set_version('2017-05-25')
    request.set_action_name('SendSms')

    request.add_query_param('RegionId', "cn-hangzhou")
    request.add_query_param('PhoneNumbers', phone_num)
    request.add_query_param('SignName', "IT教育")
    request.add_query_param('TemplateCode', "SMS_211*****")
    request.add_query_param('TemplateParam', '{\"code\":\"'+ verify_code +'\"}')

    response = client.do_action(request)

    return response

